package com.atguigu.lease.web.admin.task;

import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class LeaseAgreementTask {
    @Autowired
    private LeaseAgreementService leaseAgreementService;
    @Scheduled(cron = "0 0 0 * * ?")
    public void  leaseAgreementTask(){
        leaseAgreementService.update(new LambdaUpdateWrapper<LeaseAgreement>().lt(LeaseAgreement::getLeaseEndDate,new Date())
                .in(LeaseAgreement::getStatus, LeaseStatus.SIGNED,LeaseStatus.RENEWING,LeaseStatus.RENEWING)
                .set(LeaseAgreement::getStatus, LeaseStatus.EXPIRED));
    }
}
